
// 获取当天日期
const getDateTime = (type) => {
    // 获取当前日期
    let timestamp = Date.parse(new Date());
    let date = new Date(timestamp);
    if (type === 'day1') { //
        date.setDate(date.getDate() - 1);

    } else if (type === 'today') { // 今天
        date.setDate(date.getDate());
    } else if(type === 'day2'){
        date.setDate(date.getDate() - 2);
    }else if(type === 'day3'){
        date.setDate(date.getDate() - 3);
    }else if(type === 'day4'){
        date.setDate(date.getDate() - 4);
    }else if(type === 'day5'){
        date.setDate(date.getDate() - 5);
    }
    //获取年份
    var Y = date.getFullYear();
    //获取月份
    var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
    //获取当日日期
    var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
    return Y + '-' + M + '-' + D
};


var data = document.getElementById("data").value;
var data1 = document.getElementById("data1").value;
var data2 = document.getElementById("data2").value;
    new Chart(document.getElementById('chart-bar').getContext('2d'), {
    type: 'bar',
    data: {
    labels: [getDateTime('day5'), getDateTime('day4'), getDateTime('day3'), getDateTime('day2'), getDateTime('day1'), getDateTime('today')],
    datasets: [{
    label: '数量',
    data: [12, 19, 3, 5, 2, 3],
    backgroundColor: [
    'rgba(6,16,199,0.6)',
    'rgba(6,16,199, 0.6)',
    'rgba(6,16,199, 0.6)',
    'rgba(6,16,199, 0.6)',
    'rgba(6,16,199, 0.6)',
    'rgba(6,16,199, 0.6)'
    ],
    borderColor: [
    'rgba(6,16,199, 0.6)',
    'rgba(6,16,199, 0.6)',
    'rgba(6,16,199, 0.6)',
    'rgba(6,16,199, 0.6)',
    'rgba(6,16,199, 0.6)',
    'rgba(6,16,199, 0.6)'
    ],
    borderWidth: 1
}]
},
    options: {
    scales: {
    y: {
    beginAtZero: true
}
}
}
});
    new Chart(document.getElementById('chart-line').getContext('2d'), {
    type: 'line',
    data: {
    labels: [getDateTime('day5'), getDateTime('day4'), getDateTime('day3'), getDateTime('day2'), getDateTime('day1'), getDateTime('today')],
    datasets: [{
    label: '用户数量 单位/个',
    data: [6, 9, 6, 5, 4, 3, 2],
    fill: false,
    borderColor: 'rgba(185,110,228,.5)',
    tension: 0.1
}]
},
    options: {
    scales: {
    y: {
    beginAtZero: true
}
}
}
});
    new Chart(document.getElementById('chart-line2').getContext('2d'), {
    type: 'line',
    data: {
    labels: [getDateTime('day5'), getDateTime('day4'), getDateTime('day3'), getDateTime('day2'), getDateTime('day1'), getDateTime('today')],
    datasets: [
{
    label: '已通过',
    data: [6, 9, 6, 5, 4, 3, 12],
    fill: false,
    borderColor: 'rgba(252, 92, 125,.5)',
    tension: 0.1,
    cubicInterpolationMode: 'monotone',

},
{
    label: '未通过',
    data: [3, 8, 7, 4, 6, 10, 1],
    fill: false,
    borderColor: 'rgba(10, 191, 188,.5)',
    tension: 0.1,
    cubicInterpolationMode: 'monotone',
},
{
    label: '未审核',
    data: [1, 3, 5, 6, 7, 9, 11],
    fill: false,
    borderColor: 'rgba(221, 100, 0,.5)',
    tension: 0.1,
    cubicInterpolationMode: 'monotone',
}
    ]
},
    options: {
    scales: {
    y: {
    beginAtZero: true
}
}
}
});

    new Chart(document.getElementById('chart-doughnut').getContext('2d'), {
    type: 'doughnut',
    data: {
    labels: [
    '审核通过',
    '审核不通过',
     '未审核',
    ],
    datasets: [{
    label: 'Dataset 1',
    data: [data1,data2,data],
    backgroundColor: [
    '#0a3dbf',
    '#e84141',
        '#44a246',
    ],
    hoverOffset: 4
}]
},
    options: {
    responsive: true,
    plugins: {
    legend: {
    position: 'top',
},
    title: {
    display: true,
    text: '问卷审核数量占比图'
}
}
}
});
